Access-Control-Allow-Origin in ASP.NET Core 6
Access-Control-Allow-Origin in ASP.NET Core 6
18707-Nov-2023
Updated on 10-Nov-2023
Home / DeveloperSection / Forums / Access-Control-Allow-Origin in ASP.NET Core 6
Access-Control-Allow-Origin in ASP.NET Core 6
Aryan Kumar
10-Nov-2023In ASP.NET Core 6, you can handle CORS (Cross-Origin Resource Sharing) and specify the allowed origins using the AddCors method in the Startup.cs file. Here's a simple example:
Open your Startup.cs file.
In the ConfigureServices method, add the following code to configure CORS:
Replace "https://yourallowedorigin.com" with the actual origin you want to allow.
This will allow requests from the specified origin. Adjust the configuration according to your specific needs.
Remember to replace the placeholder with your actual domain, and you can customize other CORS settings as needed.